package jp.sourceforge.akjrcp.ui;

import java.util.Map;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GenericParametersEditorDialog extends Dialog{
private String name="";
private String comment="";
private String command="";

private String windowTitle="";//Messages.getString("explorer.convertdialog")

private int dialogWidth=450;
private int dialogHeight=350;
private Map parameters;
private GenericParametersOptionUIEditor optionEditor;
/**
 * @deprecated
 * no more support direct command input
 * @return
 */
	public String getCommand() {
	return command;
}
	/**
	 * @deprecated
	 * no more support direct command input
	 * @return
	 */
public void setCommand(String command) {
	this.command = command;
}

public String getComment() {
	return comment;
}

public void setComment(String comment) {
	this.comment = comment;
}

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

	public GenericParametersEditorDialog(Shell parentShell) {
		super(parentShell);
	}

	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(windowTitle);
	}
	
	public boolean isOpened(){
		return this.getShell()!=null && !this.getShell().isDisposed();
	}
protected Point getInitialSize(){
	return new Point(dialogWidth,dialogHeight);
	}

public void closeWindow(){
	this.close();
}

protected Control createDialogArea(Composite parent){

	/*
	 * how to limit bounds?
	 */
	Composite composite = (Composite)super.createDialogArea(parent);
	composite.setLayout(new GridLayout(1,false));
	Group label=new Group(composite,SWT.NULL);
	label.setText(Messages.getString("genericparameters.name"));
	label.setLayout(new GridLayout(1,false));
	label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	Text text=new Text(label,SWT.NULL);
	
	text.setText(name);
	text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	text.addModifyListener(new ModifyListener(){

		public void modifyText(ModifyEvent e) {
			setName(((Text) e.getSource()).getText());
		}
		
	});
	
	Group label2=new Group(composite,SWT.NULL);
	label2.setText(Messages.getString("genericparameters.comment"));
	label2.setLayout(new GridLayout(1,false));
	label2.setLayoutData(new GridData(GridData.FILL_BOTH));
	Text text2=new Text(label2,SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL);
	
	text2.setText(comment);
	GridData data=new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint=48;
	text2.setLayoutData(data);
	
	text2.addModifyListener(new ModifyListener(){

		public void modifyText(ModifyEvent e) {
			setComment(((Text) e.getSource()).getText());
		}
		
	});
	
	/*
	Group label3=new Group(composite,SWT.NULL);
	label3.setText(Messages.getString("genericparameters.command"));
	label3.setLayout(new GridLayout(1,false));
	label3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	
	Text text3=new Text(label3,SWT.NULL);
	text3.setText(command);
	text3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	text3.addModifyListener(new ModifyListener(){

		public void modifyText(ModifyEvent e) {
			setCommand(((Text) e.getSource()).getText());
		}
		
	});
	*/
	if(optionEditor!=null){
		optionEditor.createControls(composite);
		if(parameters!=null){
			optionEditor.setParameters(parameters);
		}
	}
	
	return composite;
}


protected void createButtonsForButtonBar(Composite parent) {
	   
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
            false);
   
    //add action?
    
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
            true);
}

public String getWindowTitle() {
	return windowTitle;
}

public void setWindowTitle(String windowTitle) {
	this.windowTitle = windowTitle;
}

public GenericParametersOptionUIEditor getOptionEditor() {
	return optionEditor;
}

public void setOptionEditor(GenericParametersOptionUIEditor optionEditor) {
	this.optionEditor = optionEditor;
}

public int getDialogHeight() {
	return dialogHeight;
}

public void setDialogHeight(int dialogHeight) {
	this.dialogHeight = dialogHeight;
}

public int getDialogWidth() {
	return dialogWidth;
}

public void setDialogWidth(int dialogWidth) {
	this.dialogWidth = dialogWidth;
}

public Map getParameters() {
	return parameters;
}

public void setParameters(Map parameters) {
	this.parameters = parameters;
}


}
